import { http } from '@idmy/core'

export async function allAppsForCascaders() {
  const [projects, apps] = await Promise.all<any>([http.post('/api/sys/Project/all'), http.post('/api/sys/App/all')])
  const map = new Map()
  apps.forEach(item => {
    const projectId = item.projectId
    const arr = map.get(projectId)
    if (!arr) {
      map.set(projectId, [])
    }
    map.get(projectId).push({ title: item.name, value: item.id, isLeaf: true })
  })
  return projects.map(item => {
    return {
      title: item.name,
      value: item.id,
      children: map.get(item.id) || [],
    }
  })
}
